import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from "@nestjs/common";
import { RoleMenuService } from "./role-menu.service";
import { CreateRoleMenuDto } from "./dto/create-role-menu.dto";
import { UpdateRoleMenuDto } from "./dto/update-role-menu.dto";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
import { RoleAddMenuDto } from "@/modules/role-menu/dto/role-add-menu.dto";
import { GetMenuIdByRoleIdDto } from "@/modules/role-menu/dto/getMenuIdByRoleId.dto";


@Controller("role-menu")
@ApiTags("角色与菜单相关")
@ApiBearerAuth()
export class RoleMenuController {
    constructor(private readonly roleMenuService: RoleMenuService) {
    }
    
    @Post()
    create(@Body() createRoleMenuDto: CreateRoleMenuDto) {
        return this.roleMenuService.create(createRoleMenuDto);
    }
    
    @Get()
    findAll() {
        return this.roleMenuService.findAll();
    }
    
    @Get(":id")
    findOne(@Param("id") id: string) {
        return this.roleMenuService.findOne(+id);
    }
    
    @Patch(":id")
    update(@Param("id") id: string, @Body() updateRoleMenuDto: UpdateRoleMenuDto) {
        return this.roleMenuService.update(+id, updateRoleMenuDto);
    }
    
    @Delete(":id")
    remove(@Param("id") id: string) {
        return this.roleMenuService.remove(+id);
    }
    
    @Post("roleAddMenu")
    @ApiOperation({ summary: "角色分配菜单" })
    roleAddMenu(@Body() roleAddMenuDto: RoleAddMenuDto) {
        return this.roleMenuService.roleAddMenu(roleAddMenuDto);
    }
    
    @Post("getMenuByRoleId")
    @ApiOperation({ summary: "获取当前角色下的所有菜单" })
    getMenuByRoleId(@Query() getMenuByRoleIdDto: GetMenuIdByRoleIdDto) {
        return this.roleMenuService.getMenuIdByRoleId(getMenuByRoleIdDto);
    }
}
